
    /**  
    * @Title: RequestUtil.java
    * @Package com.tzly.util
    * @Description: 
    * @author likai
    * @date 2017年6月27日
    * @version V1.0  
    */
    
package com.utils.httpservlet;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.utils.validate.Detect;


/**
    * @ClassName: RequestUtil
    * @Description: requst数据处理
    * @author likai
    * @date 2017年6月27日
    *
    */
public class RequestUtil {
	
	/*  
	    * @Description:获取requet数据
	    * 
	    * @param:													是否必须
	    * 	
	    */

	public static Map<String, String> getParams(HttpServletRequest request) {
		Map<String, String> map=new HashMap<String, String>();
		Enumeration<String> names=request.getParameterNames();
		while (names.hasMoreElements()) {
			String key = (String) names.nextElement();
			String value=request.getParameter(key);
			map.put(key, value);
		}
		return map;
	}
	
	/*  
	    * @Description:验证参数是否全部存在
	    * 
	    * @param:													是否必须
	    * 	
	    */

	public static boolean paramsIsAllExist(HttpServletRequest request) {
		Enumeration<String> names=request.getParameterNames();
		boolean exist=true;
		while (names.hasMoreElements()) {
			String key = (String) names.nextElement();
			String value=request.getParameter(key);
			if (!Detect.notEmpty(value)) {
				exist=false;
			}
		}
		return exist;
	}
	/*  
	    * @Description:验证指定参数是否全部存在
	    * 
	    * @param:													是否必须
	    * 	
	    */

	public static boolean paramsIsAllExist(HttpServletRequest request,String params) {
		String[] paramArr=params.split(",");
		boolean exist=true;
		for (int i = 0; i < paramArr.length; i++) {
			if (!Detect.notEmpty(request.getParameter(paramArr[i]))) {
				exist=false;
			}
		}
		return exist;
	}
	

}
